package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.ruoyi.system.domain.JzToursArticle;
import com.ruoyi.system.domain.vo.ScenicPointVo;
import com.ruoyi.system.domain.vo.ScenicSpotVo;
import com.ruoyi.system.mapper.JzToursArticleMapper;
import com.ruoyi.system.service.IFeginOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.JzToursShopMapper;
import com.ruoyi.system.domain.JzToursShop;
import com.ruoyi.system.service.IJzToursShopService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商家信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-18
 */
@Service
public class JzToursShopServiceImpl implements IJzToursShopService 
{
    @Autowired
    private JzToursShopMapper jzToursShopMapper;
    @Autowired
    private IFeginOutService feginOutService;
    @Autowired
    private JzToursArticleMapper jzToursArticleMapper;

    /**
     * 查询商家信息
     * 
     * @param id 商家信息ID
     * @return 商家信息
     */
    @Override
    public JzToursShop selectJzToursShopById(Long id)
    {
        return jzToursShopMapper.selectJzToursShopById(id);
    }

    /**
     * 查询商家信息列表
     * 
     * @param jzToursShop 商家信息
     * @return 商家信息
     */
    @Override
    public List<JzToursShop> selectJzToursShopList(JzToursShop jzToursShop)
    {
        return jzToursShopMapper.selectJzToursShopList(jzToursShop);
    }

    /**
     * 新增商家信息
     * 
     * @param jzToursShop 商家信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertJzToursShop(JzToursShop jzToursShop)
    {
        jzToursShop.setOutId((long)(System.currentTimeMillis()+(Math.random() * 9 + 1) * 123456564));
        //旅游景点同步
        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1001 || jzToursShop.getCateId()==1010)){
            ScenicSpotVo scenicSpotVo=new ScenicSpotVo();
            scenicSpotVo.setBrief(jzToursShop.getIntroduce());
            scenicSpotVo.setPriority(jzToursShop.getSort().intValue());
            scenicSpotVo.setName(jzToursShop.getName());
            scenicSpotVo.setLongitude(jzToursShop.getxCoordinate());
            scenicSpotVo.setLatitude(jzToursShop.getyCoordinate());
            scenicSpotVo.setPicture(jzToursShop.getCover());
            scenicSpotVo.setVoice(jzToursShop.getVoice());
            scenicSpotVo.setVoiceContent(jzToursShop.getVoiceContent());
            scenicSpotVo.setId(jzToursShop.getOutId());
            scenicSpotVo.setVideoName(jzToursShop.getVideoName());
            scenicSpotVo.setVideo(jzToursShop.getVideo());
            feginOutService.syncScenicSpot(scenicSpotVo);

        }


        //美食、住宿、文化同步接口
        //旅游景点同步
        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1005 || jzToursShop.getCateId()==1003 || jzToursShop.getCateId()==1004 ||jzToursShop.getCateId()==1007 )){
            ScenicPointVo scenicPointVo=new ScenicPointVo();

            if(jzToursShop.getCateId()==1005){

       scenicPointVo.setTypeId(3);
            }else if(jzToursShop.getCateId()==1003){

        scenicPointVo.setTypeId(1);
            }else if(jzToursShop.getCateId()==1004) {
                scenicPointVo.setTypeId(2);

            }else {

                scenicPointVo.setTypeId(4);
            }
            scenicPointVo.setBrief(jzToursShop.getIntroduce());
            scenicPointVo.setName(jzToursShop.getName());
            scenicPointVo.setLongitude(jzToursShop.getxCoordinate());
            scenicPointVo.setLatitude(jzToursShop.getyCoordinate());
            scenicPointVo.setPicture(jzToursShop.getCover());
            scenicPointVo.setId(jzToursShop.getOutId());
            feginOutService.syncServicePoint(scenicPointVo);

        }


        return jzToursShopMapper.insertJzToursShop(jzToursShop);
    }

    /**
     * 修改商家信息
     * 
     * @param jzToursShop 商家信息
     * @return 结果
     */
    @Override
    @Transactional
    public int updateJzToursShop(JzToursShop jzToursShop)
    {


        JzToursShop jzToursShop1=  jzToursShopMapper.selectJzToursShopById(jzToursShop.getId());
        //旅游景点同步
        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1001 || jzToursShop.getCateId()==1010)){
            ScenicSpotVo scenicSpotVo=new ScenicSpotVo();
            scenicSpotVo.setBrief(jzToursShop.getIntroduce());
            scenicSpotVo.setPriority(jzToursShop.getSort().intValue());
            scenicSpotVo.setName(jzToursShop.getName());
            scenicSpotVo.setLongitude(jzToursShop.getxCoordinate());
            scenicSpotVo.setLatitude(jzToursShop.getyCoordinate());
            scenicSpotVo.setPicture(jzToursShop.getCover());
            scenicSpotVo.setVoice(jzToursShop.getVoice());
            scenicSpotVo.setVoiceContent(jzToursShop.getVoiceContent());
            scenicSpotVo.setId(jzToursShop1.getOutId());
            scenicSpotVo.setVideo(jzToursShop.getVideo());
            scenicSpotVo.setVideoName(jzToursShop.getVideoName());
            feginOutService.syncScenicSpot(scenicSpotVo);

        }


        //美食、住宿、文化同步接口
        //旅游景点同步
        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1002 || jzToursShop.getCateId()==1003 || jzToursShop.getCateId()==1004 || jzToursShop.getCateId()==1005  )){


            ScenicPointVo scenicPointVo=new ScenicPointVo();
            scenicPointVo.setBrief(jzToursShop.getIntroduce());
            scenicPointVo.setName(jzToursShop.getName());
            scenicPointVo.setLongitude(jzToursShop.getxCoordinate());
            scenicPointVo.setLatitude(jzToursShop.getyCoordinate());
            scenicPointVo.setPicture(jzToursShop.getCover());
            scenicPointVo.setId(jzToursShop1.getOutId());
            feginOutService.syncServicePoint(scenicPointVo);

        }







        return jzToursShopMapper.updateJzToursShop(jzToursShop);
    }

    /**
     * 批量删除商家信息
     * 
     * @param ids 需要删除的商家信息ID
     * @return 结果
     */
    @Override
    public int deleteJzToursShopByIds(Long[] ids)
    {

        return jzToursShopMapper.deleteJzToursShopByIds(ids);
    }

    /**
     * 删除商家信息信息
     * 
     * @param id 商家信息ID
     * @return 结果
     */
    @Override
    public int deleteJzToursShopById(Long id)


    {
        JzToursShop jzToursShop=  jzToursShopMapper.selectJzToursShopById(id);

        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1001 || jzToursShop.getCateId()==1010)) {

            feginOutService.deleteScenicSpot(jzToursShop.getOutId());


        }
        if(jzToursShop.getCateId()!=null && (jzToursShop.getCateId()==1002 || jzToursShop.getCateId()==1003 || jzToursShop.getCateId()==1004 || jzToursShop.getCateId()==1005)) {

            feginOutService.deleteServicePoint(jzToursShop.getOutId());

        }


            return jzToursShopMapper.deleteJzToursShopById(id);
    }

    /**
     * 获取 酒店 文化 景区
     * @return
     */

    @Override
    public List<JzToursShop> getAllList() {
        List<JzToursShop> list=new ArrayList<>();
     //获取景区 1001
        JzToursShop jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1001);
      List<JzToursShop>  listone=jzToursShopMapper.selectJzToursShopList(jzToursShop);

        //获取酒店 1004
        jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1004);
        List<JzToursShop> listtwo=jzToursShopMapper.selectJzToursShopList(jzToursShop);



        //获取购物
        jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1007);
        List<JzToursShop> listthree=jzToursShopMapper.selectJzToursShopList(jzToursShop);

        jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1003);
        List<JzToursShop> listfour=jzToursShopMapper.selectJzToursShopList(jzToursShop);


        jzToursShop=new JzToursShop();
        jzToursShop.setCateId((long)1005);
        List<JzToursShop> listfive=jzToursShopMapper.selectJzToursShopList(jzToursShop);
        list.addAll(listone);
        list.addAll(listtwo);
        list.addAll(listthree);
        list.addAll(listfour);
        list.addAll(listfive);








        return list;
    }
}
